package com.bit.aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
@Slf4j
@Aspect
@Component
public class AspectDemo1 {
    //进行切点表达式的正确提取；
    @Pointcut("execution(* com.bit.aop.controller.*.*(..))")
    public void pt(){};
    @Around("pt()")
    public Object timeRecord(ProceedingJoinPoint pjp) throws Throwable {
//        long start=System.currentTimeMillis();
        log.info("目标方法执行前.....");
        Object result=pjp.proceed();
//        long end=System.currentTimeMillis();
        log.info("目标方法执行后......");
//        log.info(pjp.getSignature()+"执行耗时：{}ms",end-start);
        return result;
    }
    //目标方法执行前·执行的；
    @Before("pt()")
    public void doBefore(){
        log.info("doBefore............");
    }
    //目标方法执行后执行的；
    @After("pt()")
    public void doAfter(){
        log.info("doAfter.........");
    }
    //目标方法结果返回之前进行的执行；
    @AfterReturning("pt()")
    public void doAfterReturning(){
        log.info("doAfterReturning..........");
    }
    //目标方法抛出异常后执行；
    @AfterThrowing("pt()")
    public void doAfterThrowing(){
        log.info("doAfterThrowing....");
    }



}
